/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.interpreter.backends.rdf;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author Laurent WOUTERS
 */
public class TranslatorContext {
    private Map<xowl.lang.actions.QueryVariable, XOWLVariableNode> mapVariables;

    public boolean hasVariables() { return (!mapVariables.isEmpty()); }
    public Set<xowl.lang.actions.QueryVariable> getVariables() { return mapVariables.keySet(); }
    public Collection<XOWLVariableNode> getVariableNodes() { return mapVariables.values(); }
    public XOWLVariableNode getVariableNode(xowl.lang.actions.QueryVariable var) {
        if (mapVariables.containsKey(var))
            return mapVariables.get(var);
        return null;
    }
    public XOWLVariableNode getVariableNode(xowl.lang.actions.QueryVariable var, java.lang.Class type) {
        if (mapVariables.containsKey(var)) {
            XOWLVariableNode node = mapVariables.get(var);
            node.addType(type);
            return mapVariables.get(var);
        } else {
            XOWLVariableNode node = new XOWLVariableNode(var);
            node.addType(type);
            mapVariables.put(var, node);
            return node;
        }
    }

    public TranslatorContext() {
        mapVariables = new HashMap<xowl.lang.actions.QueryVariable, XOWLVariableNode>();
    }
}
